#我的项目页面功能测试类
import time

from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from common.Utils import QE_Driver

#测试问卷考试系统我的项目页面

class QE_ProjectTest:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/project"
        self.driver = QE_Driver.driver
        self.driver.get(self.url)

    #进行页面元素的查找检查
    def ProjectCheckElement(self):
        #检查页面标题元素
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > div > span")
        #检查新建按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button")
        #检查搜索框
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input")
        #检查搜索按钮
        self.driver.find_element(By.CSS_SELECTOR, "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button > span > svg")

        #添加屏幕截图
        QE_Driver.getScreenshot()

        # 功能测试
    def ProjectFunctionTest(self):
            # 测试新建功能
            # 点击新建按钮
            self.driver.find_element(By.CSS_SELECTOR,
                                     "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button").click()

            # 测试用例一：测试新建问卷调查功能

            # 选择新建问卷调查
            self.driver.find_element(By.CSS_SELECTOR,
                                     "body > div:nth-child(7) > div > div > ul > li:nth-child(1)").click()
            time.sleep(1)
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 点击保存按钮
            self.driver.find_element(By.CSS_SELECTOR,
                                     "#editor > div.survey-main-panel > div.survey-main-panel-toolbar > div:nth-child(2) > div > button.ant-btn.ant-btn-primary.ant-btn-sm").click()
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 返回到项目页面
            self.driver.back()
            self.driver.back()
            time.sleep(1)
            # 添加屏幕截图
            QE_Driver.getScreenshot()

            # 测试项目查询功能
            self.driver.find_element(By.XPATH,
                                     "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/div/div/span/span/input").send_keys(
                "请输入标题")
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            time.sleep(1)
            # 点击查询按钮
            self.driver.find_element(By.XPATH,
                                     "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[1]/div[2]/div/div/div/div/div/div/div/span/span/span/button").click()
            time.sleep(1)
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 检查是否查询成功同时验证刚刚新建功能是否保存成功
            actual = self.driver.find_element(By.XPATH,
                                              "/html/body/div[1]/div/div/div/section/div[2]/main/div/div[2]/div/div/div/div[1]/div/div/div/div[1]/div/div/div/div/div/div[1]/span[1]").text
            print(f"提示信息: {actual}")
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 断言检测一下是否符合预期
            assert actual == "请输入标题"

            # 测试用例二：测试新建在线考试功能

            # 点击新建按钮
            self.driver.find_element(By.CSS_SELECTOR,
                                     "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-heading > span > div > div > button").click()
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 选择新建在线考试
            self.driver.find_element(By.XPATH, "/html/body/div[5]/div/div/ul/li[2]").click()
            time.sleep(1)
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 点击保存按钮
            self.driver.find_element(By.XPATH,
                                     "/html/body/div[1]/div/div[2]/div/div[2]/div[1]/div[2]/div/button[5]").click()
            time.sleep(1)
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 返回到项目页面
            self.driver.back()
            self.driver.back()
            # 添加屏幕截图
            QE_Driver.getScreenshot()

            # 测试项目查询功能
            self.driver.find_element(By.CSS_SELECTOR,
                                     "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > input").send_keys(
                "考试名称")
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 点击查询按钮
            self.driver.find_element(By.CSS_SELECTOR,
                                     "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-page-header.ant-pro-page-container-warp-page-header.ant-pro-page-container-warp-page-header.ant-page-header-has-breadcrumb.ant-page-header-ghost > div.ant-page-header-content > div > div > div > div > div > div > div > span > span > span > button > span > svg").click()
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 检查是否查询成功同时验证刚刚新建功能是否保存成功
            actual = self.driver.find_element(By.CSS_SELECTOR,
                                              "#sk-layout > div > div > section > div.ant-pro-layout-container > main > div > div.ant-pro-grid-content > div > div > div > div.ant-list.ant-list-split.ant-list-grid.survey-home-content > div > div > div > div > div > div > div > div > div > div.card-header > span.survey-title").text
            print(f"项目名称: {actual}")
            # 添加屏幕截图
            QE_Driver.getScreenshot()
            # 断言检测一下是否符合预期
            assert actual == "考试名称"

        # project = QE_ProjectTest()
        # project.ProjectCheckElement()
        # project.ProjectFunctionTest()

        # 指定浏览器的退出
        # QE_Driver.driver.quit()